package com.itheima.health.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.health.dao.MenuDao;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.pojo.Menu;
import com.itheima.health.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zhangmeng
 * @description
 * @date 2019/9/18
 **/
@DubboService
@Slf4j
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuDao menuDao;

    @Transactional
    @Override
    public void add(Menu menu) {
        log.info("[菜单项-添加]data:{}",menu);
        // 插入基本数据
        menuDao.insert(menu);
    }

    @Transactional
    @Override
    public void delete(Integer id) {
        log.info("[菜单项-删除]data:{}",id);
        // 删除基本数据
        menuDao.deleteById(id);
    }

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        log.info("[菜单项-分页查询]data：{}",queryPageBean);
        //设置分页参数
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //查询page
        Page<Menu> page= menuDao.selectByCondition(queryPageBean.getQueryString());
        //封装返回值
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public Menu findById(Integer id) {
        return menuDao.selectById(id);
    }


    @Transactional
    @Override
    public void edit(Menu Menu) {
        //1、更新菜单项
        menuDao.update(Menu);
    }


}
